﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage
{
    public partial class manage_log : System.Web.UI.Page
    {
        LoginLogBLL llbll = new LoginLogBLL();

        int pageSize = 20;
        int pageCount = 0;
        public int CurrentIndex
        {
            get { return Convert.ToInt32(ViewState["index"]); }
            set { ViewState["index"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
        public void BindData()
        {
            CurrentIndex = Convert.ToInt32(Request.QueryString.Get("page"));
            if (CurrentIndex == 0)
            {
                CurrentIndex = 1;
            }
            IList<LoginLog> loglist = new List<LoginLog>();
            loglist = llbll.GetLoginLogListByPaging(CurrentIndex,pageSize );
            pageCount = llbll.GetLoginLogListByPaging();
            GridView1.DataSource = loglist;
            GridView1.DataBind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            int id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName.Equals("btnDel"))
            {
                try
                {
                    llbll.Delete("LoginLog",id); ScriptManager.RegisterClientScriptBlock(this, GetType(), "js", "alert('删除成功')", true);
                }
                catch
                {

                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "js", "alert('删除失败')", true);
                }

                BindData();
            }
            else if (e.CommandName.Equals("btnEdit"))
            {
                Response.Redirect("add_rczp.aspx?id=" + id);
            }

        }
        public string GetPager()
        {

            return EnPager.GetPager(pageCount, pageSize, CurrentIndex, "");
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindData();
        }
        #region

        WorkerBLL wbll = new WorkerBLL();
        public string GetName(object obj)
        {
            string ids = obj.ToString();
            if (ids.Length >= 1)
            {
                string[] idstr = ids.Split(',');
                string name = "";
                try
                {
                    for (int i = 0; i < idstr.Length; i++)
                    {
                        if (idstr[i].Length > 0 && !idstr[i].Equals(""))
                        {
                            name += ((Worker)wbll.FindModelById("Worker", Convert.ToInt32(idstr[i]))).RealName ;
                        }
                    }
                    return name;
                }
                catch (Exception)
                {
                    return "未知";
                }
            }
            else
            {
                return "未知";
            }
        }

        #endregion
    }
}
